home *** CD-ROM | disk | FTP | other *** search
/ Aminet 41 / Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso / Aminet / comm / tcp / rxsocket.lha / rxsocket / examples / nntp.rexx < prev    next >
OS/2 REXX Batch file  |  2000-11-28  |  2KB  |  95 lines

  1. /* a very simple news protocol POST client
  2.    Usage: nntp <group_name> <subject> <file_to_send>
  3. */
  4.  
  5. /* SET THESE */
  6.  
  7. host     = ""                  /* news host name  */
  8. port     = 119                 /* port            */
  9. RealName = ""                  /* your name       */
  10. email    = ""                  /* your email addr */
  11. gmtoff   = "+0100"             /* gmt offset      */
  12.  
  13. /****/
  14.  
  15. l="rmh.library";if ~show("L",l) then;if ~addlib(l,0,-30) then exit
  16. if AddLibrary("rexxsupport.library","rxsocket.library")~=0 then exit
  17.  
  18. prg=ProgramName("NOEXT")
  19. if ~RMH_ReadArgs("GROUP/A,SUBJECT/A,FILE/A") then do
  20.     call PrintFault()
  21.     exit
  22. end
  23.  
  24. if ~open(in,parm.2.value) then do
  25.     call PrintFault()
  26.     exit
  27. end
  28.  
  29. say "opening connection..."
  30. sock = OpenConnection("tcp",port,host)
  31. if sock<0 then do
  32.     select
  33.         when sock=-2 then say prg": can't find <"host">"
  34.         otherwise say prg": can't connect <"host":"port">" errorstring()
  35.     end
  36.     exit
  37. end
  38.  
  39. say "entering..."
  40. call rec
  41.  
  42. say "sending message..."
  43. call sen "POST"
  44. call rec
  45.  
  46. if GetSockName(sock,"LOCALE")<0 then do
  47.     say prg": can't find socket locale infos"
  48.     exit
  49. end
  50. thisHost=locale.addraddr
  51.  
  52. msg=,
  53. "From:" realname "<"email">" || "D0A"x ||,
  54. "Newsgroups:" parm.0.value || "D0A"x ||,
  55. "Date:" date() time() gmtoff || "D0A"x ||,
  56. "Message-ID: <smtp"time(s)"@"thisHost">" || "D0A"x ||,
  57. "X-Newsposter: nntp.rexx - Amiga ARexx nntp sender" || "D0A"x ||,
  58. "Subject:" parm.1.value || "D0A"x
  59. call sen msg
  60.  
  61. do while ~eof(in)
  62.     blk=readch(in,512)
  63.     if blk~="" then call sen blk
  64. end
  65.  
  66. call sen "D0A"x || "."
  67. call rec
  68.  
  69. call sen "QUIT"
  70. call rec
  71.  
  72. say "done."
  73. exit
  74.  
  75. sen:
  76. parse arg string
  77.     string=string || "D0A"x
  78.     if send(sock,string)~=length(string) then do
  79.         say prg": send error" ErrorString()
  80.         exit
  81.     end
  82.     return
  83.  
  84. rec:
  85.     if recv(sock,"BUF",256)<0 then do
  86.         say prg": recv error" ErrorString()
  87.         exit
  88.     end
  89.     parse var BUF code rest "D0A"x
  90.     if code>=400 then do
  91.         say "error from server: ("code")"rest
  92.         exit
  93.     end
  94.     return
  95.